import axios from "axios"
import { RequestParams } from "./types"
//axios配置
axios.defaults.baseURL = "http://localhost:3000"
axios.defaults.headers.common["Access-Control-Allow-Origin"] = "*"
// axios.defaults.headers.common["Content-Type"] = "multipart/form-data"
// axios.defaults.headers.post["Content-Type"] = "multipart/form-data"
axios.defaults.baseURL = "/api"

//封装请求方法
export function request(config: RequestParams) {
  const { url, method, params, isFile } = config
  //   if (isFile) {
  //     axios.defaults.headers.common["Content-Type"] = "multipart/form-data"
  //   }
  return new Promise((resolve, reject) => {
    axios({
      method: method,
      url: url,
      params: params,
      headers: {
        "Content-Type": "multipart/form-data",
      },
    })
      .then((res) => {
        resolve(res)
      })
      .catch((error) => {
        reject(error)
      })
  })
}
